﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Truextend.Training.Model.Entities;

namespace Truextend.Training.Business.Utility
{
    public static class GeneratorScheduleCourse
    {
        public static List<ScheduleCourse> GetScheduleCourse(DateTime startDate, DateTime endDate, DateTime startTime, DateTime endTime, List<string> days)
        {
            List<ScheduleCourse> scheduleCourseList = new List<ScheduleCourse>();

            
            DateTime currentDate = startDate;
            while( currentDate <= endDate )
            {
                ScheduleCourse scheduleCourse = GetDay(currentDate, days, startTime, endTime);
                if (scheduleCourse != null)
                {
                    scheduleCourseList.Add(scheduleCourse);
                }
                currentDate = currentDate.AddDays(1);                
            }

            return scheduleCourseList;
        }

        public static ScheduleCourse GetDay(DateTime date, List<string> days, DateTime startTime, DateTime endTime)
        {
            string day = date.ToString("dddd");
            foreach (string d in days)
            {
                if (day.Equals(d))
                {
                    ScheduleCourse scheduleCourse = new ScheduleCourse();
                    scheduleCourse.StartTime = new DateTime(date.Year, date.Month, date.Day, 
                                                startTime.Hour, startTime.Minute, startTime.Second);
                    scheduleCourse.EndTime = new DateTime(date.Year, date.Month, date.Day, 
                                                endTime.Hour, endTime.Minute, endTime.Second);
                    return scheduleCourse;
                }
            }
            
            return null;
        }
    }
}
